home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
menuba.zip
/
TEST.ZIP
/
TEST.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-01-25
|
4KB
|
123 lines
/****************************************************************************
PROGRAM: Test.c
****************************************************************************/
#include "windows.h"
#include "menudefs.h"
#include "stdlib.h"
WORD hDlgItem;
static int nItems,ItemCount,SelectItem;
char temp [10];
BOOL FAR PASCAL TestProc(HWND, unsigned, WORD, LONG);
int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
HANDLE hInstance;
HANDLE hPrevInstance;
LPSTR lpCmdLine;
int nCmdShow;
{ FARPROC lpTestProc;
lpTestProc = MakeProcInstance(TestProc, hInstance);
DialogBox(hInstance, "TESTBOX", NULL, lpTestProc);
FreeProcInstance(lpTestProc);
return (TRUE);
}
/****************************************************************************/
BOOL FAR PASCAL TestProc(hDlg, message, wParam, lParam)
HWND hDlg;
unsigned message;
WORD wParam;
LONG lParam;
{ char str[17];
HWND hCtl;
int i;
switch (message)
{
case WM_INITDIALOG:
nItems=0;
ItemCount=0;
hCtl = GetDlgItem( hDlg, 100 ); /* combobox id */
SetFocus(hCtl);
SelectItem=-1;
return (TRUE);
break;
case WM_COMMAND:
switch(wParam)
{
case 1: /* ok */
EndDialog(hDlg, TRUE);
return (TRUE);
break;
case 100: /* select item */
hCtl = GetDlgItem( hDlg, 100 ); /* combobox id */
SelectItem=(int)SendMessage( hCtl, CB_GETCURSEL, 0, (LONG)(LPSTR)0 );
break;
case 101: /* add item */
++nItems;
++ItemCount;
SelectItem=ItemCount-1;
itoa(nItems,str,10);
lstrcpy((LPSTR)temp,(LPSTR)"Item");
lstrcat((LPSTR)temp,(LPSTR)str);
hCtl = GetDlgItem( hDlg, 100 ); /* combobox id */
SendMessage( hCtl, CB_ADDSTRING, 0, (LONG)(LPSTR)temp);
SendMessage( hCtl, CB_SETCURSEL, (WORD) ItemCount-1, (LONG)(LPSTR) 0 );
hCtl = GetDlgItem( hDlg, 110 ); /* static text id */
lstrcat((LPSTR)temp,(LPSTR)" added");
SetWindowText(hCtl,temp);
break;
case 102: /* modify item */
/* Get index of list box control selection. */
hCtl = GetDlgItem( hDlg, 100 ); /* combobox id */
if(SelectItem>=0)
{ /* modify */
SendMessage( hCtl, CB_DELETESTRING, SelectItem, (LONG)(LPSTR)NULL);
++nItems;
itoa(nItems,str,10);
lstrcpy((LPSTR)temp,(LPSTR)"Item");
lstrcat((LPSTR)temp,(LPSTR)str);
SendMessage( hCtl, CB_INSERTSTRING, SelectItem, (LONG)(LPSTR)temp);
SendMessage( hCtl, CB_SETCURSEL, (WORD) SelectItem, (LONG)(LPSTR) 0 );
hCtl = GetDlgItem( hDlg, 110 ); /* static text id */
lstrcat((LPSTR)temp,(LPSTR)" Added");
SetWindowText(hCtl,temp);
}
break;
case 103: /* delete item */
/* Get index of list box control selection. */
hCtl = GetDlgItem( hDlg, 100 ); /* combobox id */
if(SelectItem>=0)
{ /* delete */
SendMessage( hCtl, CB_DELETESTRING, SelectItem, (LONG)(LPSTR)NULL);
--ItemCount;
SendMessage( hCtl, CB_SETCURSEL, (WORD) 0, (LONG)(LPSTR) 0 );
hCtl = GetDlgItem( hDlg, 110 ); /* static text id */
SetWindowText(hCtl,"Item Deleted");
}
break;
case 104: /* display item */
/* Get index of list box control selection. */
hCtl = GetDlgItem( hDlg, 100 ); /* combobox id */
i=(int)SendMessage( hCtl, CB_GETCURSEL, 0, (LONG)(LPSTR)0 );
lstrcpy((LPSTR)temp,(LPSTR)"");
SendMessage( hCtl, CB_GETLBTEXT,i, (LONG)(LPSTR)temp);
MessageBox(hDlg,(LPSTR)temp,"Selection",MB_OK);
break;
case 105: /* display count */
itoa(ItemCount,temp,10);
MessageBox(hDlg,(LPSTR)temp,"Count",MB_OK);
break;
}
return (TRUE);
}
return (FALSE);
}